package org.example.main.multi_threading.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.atomic.AtomicInteger;

@AllArgsConstructor
@NoArgsConstructor
public class Station extends Thread {
    private  String name;
    private  AtomicInteger totalCount;

    @Override
    public void run() {
        //totalCount.decrementAndGet()  获取当前数量-1后的结果
        while (totalCount.get() > 0) {
            totalCount.decrementAndGet();
            System.out.println(name+"当前票数剩余："+totalCount.get());
            System.out.println(name + "站:售出车票1张");
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(name + "站:车票已售完。");
        System.out.println("最后："+totalCount.get());
    }
}
